local skel = fk.CreateSkill {
  name = "emo__huaigu",
}

Fk:loadTranslationTable{
  ["emo__huaigu"] = "怀顾",
  [":emo__huaigu"] = "你使用一张“转运”花色牌、无色牌时，或受到1点伤害后，可以摸一张牌，并随机获得一张“转运”花色的牌。",

  ["#emo__huaigu-choice"] = "请选择一种“转运”花色，摸一张此花色的牌",

  ["$emo__huaigu1"] = "吃",
  ["$emo__huaigu2"] = "碰",
  ["$emo__huaigu3"] = "槓",
  ["$emo__huaigu4"] = "荣",
}

---@param player ServerPlayer
local on_use = function (self, event, target, player, data)
  local room = player.room
  player:drawCards(1, skel.name)
  if not player.dead then
    local choices = player:getTableMark("@emo__zhuanyun")
    if #choices > 0 then
      --[[
      local all_choices = {"log_spade", "log_heart", "log_club", "log_diamond"}
      local choice = room:askToChoice(player, {
        choices = choices, skill_name = skel.name, prompt = "#emo__huaigu-choice", all_choices = all_choices,
      })
      --]]
      local choice = table.random(choices)
      local ids = room:getCardsFromPileByRule(".|.|"..string.sub(choice, 5), 1, "allPiles")
      if #ids > 0 then
        room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skel.name)
      end
    end
  end
end

skel:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and
    (data.card.color == Card.NoColor or table.contains(player:getTableMark("@emo__zhuanyun"), data.card:getSuitString(true)))
  end,
  on_use = on_use,
})

skel:addEffect(fk.Damaged, {
  anim_type = "drawcard",
  trigger_times = function (self, event, target, player, data)
    return data.damage
  end,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
  end,
  on_use = on_use,
})

return skel
